package test1225;

public class Test15 {
    public static void main(String[] args) {
        // 统计出数组中各个元素以及出现的次数
        int[] arr = {1,2,3,4,1,2,3,5,4,2};
        m15(arr);
    }
    public static void m15(int[] arr) {
        int[] m = new int[max(arr) + 1];
        for (int i = 0; i < arr.length; i++)  {
            int num = arr[i];
            m[num]++;
        }
        for (int i = 0; i < m.length; i++) {
            if(m[i] > 0){
                System.out.println(i + "出现了" + m[i] + "次");
            }
        }
    }
    public static int max(int[] arr) {
        int max = arr[0];
        for(int i = 1; i < arr.length; i++) {
            if(max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }

}
